<?php
    $xtpl_mid   = new XTemplate("view/mid.htm");

	if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
		$pid=$_REQUEST['productid'];
		addtocart($pid,1);
		header("location:index.php?page=cart&module=cart");
		exit();
	}
    
    $offset     = $_GET['p'];
    $limit      = 9;
    $offset     = (isset($offset) && ($offset > 0)) ? $offset : 0;
    
    $query          = "SELECT count(*) AS totalRecords FROM product";
    $re             = mysql_query($query);
    $rows           = mysql_fetch_assoc($re);
    $totalRecords   = $rows['totalRecords'];
    
    $pages  = pagging($totalRecords, $offset, $limit);
    $sql    = "SELECT * FROM product ORDER BY id_p DESC LIMIT " . $offset . ", " . $limit . "";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
        $xtpl_mid   -> assign('id1' , $row['id_p']);
        $xtpl_mid   -> assign('image', $row['image']);
        $xtpl_mid   -> assign('id2' , $row['id_p']);
        $xtpl_mid   -> assign('milkname', $row['milkname']);
        $xtpl_mid   -> assign('id3' , $row['id_p']);
        $xtpl_mid   -> assign('cost', $row['cost']);
        $xtpl_mid   -> insert_loop('MID.TABLES', array('MID'=>$row));
    }
    
    $xtpl_mid   -> parse("MID");
    $mid        = $xtpl_mid -> text("MID");
?>